Add SSH key anonymization with --anonymize-ssh-keys flag#248
Open
manonfgoo wants to merge 2 commits into
Open
Conversation
Add support for anonymizing SSH public key blobs in authentication and known-hosts lines. Supports RSA, DSA, ECDSA, and Ed25519 key types. Replacement is deterministic from --salt and length-preserving while maintaining the SSH wire format key type header.
Fixes mypy no-untyped-def errors for all 5 functions in the module. Also corrects the ssh_key_regexes type hint in FileAnonymizer from tuple[Pattern, int] to tuple[Pattern, str] to match the actual group name strings returned by generate_ssh_key_regexes().
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a new
--anonymize-ssh-keysflag that anonymizes SSH public key blobs in network device configurations. This complements the existing--anonymize-passwords(-p) flag, which previously scrubbed SSH key lines entirely (replacing the whole line withSCRUBBED).Key design decisions:
-p: SSH key anonymization is opt-in via its own flag. The oldssh-(rsa|dsa)regex in the-ppassword regexes has been commented out to avoid double-processing.--salt: Uses HMAC-SHA256 keyed by the salt, so the same key always maps to the same replacement across runs.Supported formats
ssh-rsa,ssh-dsa,ssh-ecdsa,ssh-ed25519, and bareecdsa-sha2-nistp*(NX-OS/Arista)rsa-key,dsa-key,ed25519-key,ecdsa-sha2-nistp*-keykey-hash ssh-rsa <32-hex-MD5>Files changed
netconan/ssh_key_anonymization.pynetconan/anonymize_files.pyanon_ssh_keysparam and callreplace_ssh_keys()in the processing pipelinenetconan/netconan.py--anonymize-ssh-keysCLI argumentnetconan/default_pwd_regexes.pyssh-(rsa|dsa)scrub regex (now handled by the new module)README.rst.github/workflows/test.ymlpasslibto CI deps (already a project dependency, needed for test environment)tests/unit/test_ssh_key_anonymization.pytests/end_to_end/test_e2e_ssh_keys.pyTest plan
main()→ output file with anonymized keys-pno longer scrubs SSH key lines--anonymize-ssh-keysworks both alone and combined with-pand-aThis change is